class GuideUI extends UIBase{
    private container:egret.DisplayObjectContainer;
    private lb_tips:eui.Label;
    private spt_hand:eui.Image;
    private line:eui.Rect;

    public constructor(data)
    {
        super('GuideView', data);
        GuideManager.instance().isInGuide = true;
    }

    public init()
    {
        this.width = GlobalManager.instance().curWidth();
        this.height = GlobalManager.instance().curHeight();
        this.setUI();
        if(this.data.isShowMask)
        {
            let maskIcon:egret.Shape;
            if(this.data.type == 0)
            {
                maskIcon = this.addCirlce(this.data.radius);
            }
            else
            {
                maskIcon = this.addRectangle(this.data.width, this.data.height);
            }
            maskIcon.x = this.data.x;
            maskIcon.y = this.data.y;

            this.drawMask(maskIcon, this.width, this.height);
        }
    }

    //添加圆形可点击区域
    protected addCirlce(radius:number)
    {
        let maskIcon:egret.Shape = new egret.Shape();
        maskIcon.graphics.beginFill(0x000000, 1);
        maskIcon.graphics.drawCircle(0, 0, radius);
        maskIcon.graphics.endFill();
        return maskIcon;
    }   

    //添加矩形可点击区域
    protected addRectangle(width:number, height:number)
    {
        let maskIcon:egret.Shape = new egret.Shape();
        maskIcon.graphics.beginFill(0x000000, 1);
        maskIcon.graphics.drawRect(0, 0, width, height);
        maskIcon.graphics.endFill();
        return maskIcon;
    } 

    /**
     * dp 确保已经定位并且没有加入到显示列表中。
     */
    public drawMask(dp:egret.DisplayObject, w:number, h:number):void {
        if(!this.container)
        {
            this.container = new egret.DisplayObjectContainer(); 
        }

        let bg:egret.Shape = new egret.Shape();
        bg.graphics.beginFill(0x000000, 0.6);
        bg.graphics.drawRect(0, 0, w, h);
        bg.graphics.endFill();

        this.container.addChild(bg);
        this.container.addChild(dp);

        dp.blendMode = egret.BlendMode.ERASE;

        let renderTexture:egret.RenderTexture = new egret.RenderTexture();
        renderTexture.drawToTexture(this.container);

        let bitmap:egret.Bitmap = new egret.Bitmap(renderTexture);
        this.addChildAt(bitmap, 0);
        bitmap.pixelHitTest = true;
    }

    public setUI()
    {
       
    }

    protected touchHandle()
    {
        if(GuideManager.instance().curGuideId == 1 && GuideManager.instance().curGuideSubId ==2)
        {
            GuideManager.instance().postGuideStepChange();
        }
        this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchHandle, this);
    }

    public showHandEffect(type)
    {
        if(type == 1)
        {
            EffectUtil.instance().MoveEffect(this.spt_hand);
        }
        else
        {
            EffectUtil.instance().MoveEffect2(this.spt_hand);
        }
    }

    public clear()
    {
        super.clear();
        EffectUtil.instance().StopEffect(this.spt_hand);
        this.container = null;
    }
}